/**
 * 
 */
package com.dsteiner.xelavos.client;


import com.dsteiner.widgets.client.DateUtilImpl;
import com.dsteiner.widgets.client.JsUtil;
import com.dsteiner.widgets.client.PrefilledDateBox;
import com.dsteiner.widgets.client.PrefilledRichTextArea;
import com.dsteiner.widgets.client.PrefilledTextArea;
import com.dsteiner.widgets.client.SuggestBoxWidget;
import com.dsteiner.widgets.client.Widgets.FlowPanelExt;
import com.dsteiner.widgets.client.Widgets.LazyWidget;
import com.dsteiner.widgets.client.model.PrefilledTextBoxModel;
import com.dsteiner.widgets.client.model.SuggestBoxModel;
import com.dsteiner.xelavos.client.constants.Constants;
import com.dsteiner.xelavos.client.controller.CreateJobController;
import com.dsteiner.xelavos.client.model.CreateObjectModel;
import com.dsteiner.xelavos.client.model.MainTabModel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.datepicker.client.DatePicker;

public class CreateJobWidget extends LazyWidget {

	private final CreateJobController createJobController;
	private final CreateObjectModel createObjectModel;
	private final MainTabModel mainTabModel;

	public CreateJobWidget(CreateJobController createJobController, CreateObjectModel createObjectModel,
			MainTabModel mainTabModel) {
		this.createJobController = createJobController;
		this.createObjectModel = createObjectModel;
		this.mainTabModel = mainTabModel;
	}
	
	@Override
	public Widget createContentWidget() {
		FlowPanelExt mainPanel = new FlowPanelExt();
		SuggestBoxModel nameTextBoxModel = new SuggestBoxModel();
		SuggestBoxWidget nameTextBox = new SuggestBoxWidget(nameTextBoxModel, new SelectedTabSuggestBoxDataProvider(mainTabModel));
		nameTextBoxModel.setDefaultText("<span class=\"main\">nombre</span> <span class=\"requiredField\">*</span> (ej Vendedor)");
		SuggestBoxModel empleadorTextBoxModel = new SuggestBoxModel();
		SuggestBoxWidget empleadorTextBox = new SuggestBoxWidget(empleadorTextBoxModel, new SelectedTabSuggestBoxDataProvider(mainTabModel));
		empleadorTextBoxModel.setDefaultText("<span class=\"main\">empleador</span> (ej Pollo Campero)");
		PrefilledTextBoxModel descriptionTextBoxModel = new PrefilledTextBoxModel();
		descriptionTextBoxModel.setDefaultText("<span class=\"main\">descripcion</span> <span class=\"requiredField\">*</span> (ej 3 anos de experiencia en vender pollo)");
		PrefilledRichTextArea descriptionTextBox = new PrefilledRichTextArea(descriptionTextBoxModel);
		PrefilledTextBoxModel contactTextBoxModel = new PrefilledTextBoxModel();
		contactTextBoxModel.setDefaultText("<span class=\"main\">contacto</span> <span class=\"requiredField\">*</span> (ej direccion y/o email y/o telefono)");
		PrefilledTextArea contactTextBox = new PrefilledTextArea(contactTextBoxModel);
		PrefilledTextBoxModel validUntilTextBoxModel = new PrefilledTextBoxModel();
		validUntilTextBoxModel.setDefaultText("<span class=\"main\">valido hasta</span> (ej 24/12/2009)");
		DatePicker datePicker = new DatePicker();
		PrefilledDateBox validUntilDateTextBox = new PrefilledDateBox(validUntilTextBoxModel, datePicker, DateUtilImpl.formatterSpanish);

		contactTextBoxModel.setMaxCount(Constants.MAX_COUNT_STRING);
		
		mainPanel.add((Widget)nameTextBox);
		mainPanel.add((Widget)empleadorTextBox);
		mainPanel.add((Widget)validUntilDateTextBox);
		mainPanel.add((Widget)contactTextBox);
		mainPanel.add((Widget)descriptionTextBox);
		
		nameTextBox.setTabIndex(95);
		empleadorTextBox.setTabIndex(96);
		validUntilDateTextBox.setTabIndex(97);
		contactTextBox.setTabIndex(98);
		descriptionTextBox.setTabIndex(99);

		nameTextBox.getElement().getStyle().setZIndex(10);
		empleadorTextBox.getElement().getStyle().setZIndex(9);
		validUntilDateTextBox.getElement().getStyle().setZIndex(8);
		contactTextBox.getElement().getStyle().setZIndex(7);
		descriptionTextBox.getElement().getStyle().setZIndex(6);
		
		createJobController.registerJsUtil(JsUtil.getInstance());
		createJobController.registerNameTextBoxModel(nameTextBoxModel);
		createJobController.registerEmpleadorTextBoxModel(empleadorTextBoxModel);
		createJobController.registerDescriptionTextBoxModel(descriptionTextBoxModel);
		createJobController.registerContactTextBoxModel(contactTextBoxModel);
		createJobController.registerValidUntilTextBoxModel(validUntilTextBoxModel);
		createJobController.registerCreateObjectModel(createObjectModel);
		createJobController.registerCreateObjectWidget(this);
		
		return mainPanel;
	}
}